package com.hzh.jetpackcomposecompositionlocal

import androidx.compose.material3.Text
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith

/**
 * @author huangzehui
 * @date 17/8/2025 下午9:19 周日
 * @description 隐式传参
 */
@RunWith(AndroidJUnit4::class)
class ImplicitTest {
    var color = "黑色"

    private fun Layout() {
        Text()
        provider("红色") {
            Grid()
        }
        Text()
        Text()
    }

    private fun provider(value: String, content: (() -> Unit)) {
        // 方法执行前，修改全局变量
        color = value
        content()
        // 方法执行完之后，修改回来
        color = "黑色"
    }

    private fun Grid() {
        println("other components in Grid")
        Text()
    }

    private fun Text() {
        println("Text")
        println(color)
    }

    @Test
    fun test_implicit() {
        Layout()
    }

}